/**
 * 　　┏┓　　　┏┓+ +
 * 　┏┛┻━━━┛┻┓ + +
 * 　┃　　　　　　　┃
 * 　┃　　　━　　　┃ ++ + + +
 * ████━████ ┃+
 * 　┃　　　　　　　┃ +
 * 　┃　　　┻　　　┃
 * 　┃　　　　　　　┃ + +
 * 　┗━┓　　　┏━┛
 * 　　　┃　　　┃
 * 　　　┃　　　┃ + + + +
 * 　　　┃　　　┃
 * 　　　┃　　　┃ +  神兽保佑
 * 　　　┃　　　┃    代码无bug
 * 　　　┃　　　┃　　+
 * 　　　┃　 　　┗━━━┓ + +
 * 　　　┃ 　　　　　　　┣┓
 * 　　　┃ 　　　　　　　┏┛
 * 　　　┗┓┓┏━┳┓┏┛ + + + +
 * 　　　　┃┫┫　┃┫┫
 * 　　　　┗┻┛　┗┻┛+ + + +
 */
package com.handpay.zztong.hp.base.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.handpay.framework.utils.UserCheckTimeout;
import com.handpay.framework.utils.Heart;
import com.handpay.zztong.hp.bean.ResponseBean;
import com.handpay.zztong.hp.main.activity.MainActivity;
import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.ZZTApplication;
import com.handpay.zztong.hp.bean.ActionBar;
import com.handpay.zztong.hp.config.ZZTConstant;
import com.handpay.zztong.hp.main.fragment.HomeFragment;
import com.handpay.zztong.hp.main.fragment.MyFragment;
import com.handpay.zztong.hp.main.fragment.ReceivablesFragment;
import com.handpay.zztong.hp.main.model.FunctionInfo;

import java.util.Hashtable;
import java.util.Map;

@SuppressLint("NewApi")
public class BaseFragment extends Fragment {
    private static final String TAG = "BaseFragment";
    protected int newWidth = 80;
    protected Context mActivity;
    protected MainActivity mainActivity;
    public int width, height = 1920;
    // T0资质拍照入口开关 0:关闭，1:开启
    public int isOpenT0switch = 0;
    //因为 收款和个人页面都需要调用查询身份证过期接口
    public int mCertNoExpiryDate = -1;
    public UserCheckTimeout chekUserTimeout;
    protected ViewGroup mViewGroup = null;
    protected float density;

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity = this.getActivity();
        mainActivity = (MainActivity) mActivity;
        newWidth = this.getActivity().getResources().getDisplayMetrics().widthPixels;
        chekUserTimeout = new UserCheckTimeout(getActivity());//时间默认十分钟可以自己设置

        width = mainActivity.getResources().getDisplayMetrics().widthPixels;// 屏幕的宽度
        height = mainActivity.getResources().getDisplayMetrics().heightPixels;// 屏幕的高度
    }

    public void refreshActionBar(MainActivity mainActivity) {
        if (mainActivity == null) {
            return;
        }
    }

    public String getFragmentTitle() {
        return ZZTConstant.FRAGMENT_FLAG_HOME;
    }

    public ActionBar getFragmentActionBar() {
        if (checkMyActivityIsNull()) {
            mActivity = ZZTApplication.getInstance().getApplicationContext();
        }
        return null;
    }

    public boolean checkMyActivityIsNull() {
        return mActivity == null;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        refreshActionBar((MainActivity) mActivity);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    public static BaseFragment newInstance(Context context, String tag) {
        BaseFragment baseFragment = null;
        if (TextUtils.equals(tag, ZZTConstant.FRAGMENT_FLAG_HOME)) {
            baseFragment = new HomeFragment();
        } else if (TextUtils.equals(tag, ZZTConstant.FRAGMENT_FLAG_RECEIVABLES)) {
            baseFragment = new ReceivablesFragment();
        } else if (TextUtils.equals(tag, ZZTConstant.FRAGMENT_FLAG_MY)) {
            baseFragment = new MyFragment();
        }
        return baseFragment;
    }

    public Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            setCurrentItem(msg.what);
            super.handleMessage(msg);
        }
    };


    public void setCurrentItem(int index) {

    }

    public boolean netResponse(String action, Hashtable<String, Object> resp, boolean showAlert, DialogInterface.OnClickListener on, boolean isDataCompile) {
        return checkMyActivityIsNull();
    }

    public boolean netJsonResponse(String action, ResponseBean resp, boolean showAlert, DialogInterface.OnClickListener on) {
        return checkMyActivityIsNull();
    }


    /***
     * 操作超時，清空用戶数据并重新登录
     */
    public void goLoginWithTimeOut() {
        mainActivity.showAlertDialog(getActivity(), getString(R.string.time_out_title), getString(R.string.time_out), false, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //重新登录
                mainActivity.exitAccount();
            }
        });
    }

    public void swiperSelect(Intent intent) {
    }

    public void doShouKuanXianE() {
    }

    public void onVPOS() {
    }

    public void doZiZhiTiJiao() {
    }
}